<%@page import="java.util.Date"%>
<%@page import="com.iflysse.bbs.model.ReplyInfo"%>
<%@page import="com.iflysse.bbs.dao.impl.ReplyDaoImpl"%>
<%@page import="com.iflysse.bbs.dao.ReplyDao"%>
<%@page import="com.iflysse.bbs.model.UserInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="base.jsp"%>
<%
	String reply = request.getParameter("reply") == null ? null
			: request.getParameter("reply").toString().trim();
	String newsid = request.getParameter("newsid") == null ? null
			: request.getParameter("newsid").toString().trim();
	UserInfo user = null;
	if (session.getAttribute("currentUser") != null) {
		user = (UserInfo) session.getAttribute("currentUser");
	}
	
	if(reply == null || request == null || user == null){
		String script = "<script>parent.art.dialog.list['login'].close();</script>";
		out.print(script);
		return;
	}
	
	ReplyInfo replyInfo = new ReplyInfo();
	replyInfo.setContent(reply);
	replyInfo.setDate(new Date(System.currentTimeMillis()));
	replyInfo.setNewsId(Integer.valueOf(newsid).intValue());
	replyInfo.setUserId(user.getId());
	
	ReplyDao replyDao = new ReplyDaoImpl();
	boolean flag = replyDao.add(replyInfo);
	if(flag){
		String url = "view_handler.jsp?newsid=" + newsid;
		response.sendRedirect(url);
	}else{
		String script = "<script>parent.art.dialog.list['login'].close();</script>";
		out.print(script);
		return;
	}
%>
